<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>薪资标准设定</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script src="../js/jquery-3.1.1.min.js"></script>
    <script src="../layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script src="../js/log-wage/wageNormForm.js"></script>
</head>
<body>
<div>
    <div>
        <form>
            <div class="layui-inline">
                <label class="layui-form-label">关键字</label>
                <div class="layui-input-block">
                    <input type="text" name="norm" lay-verify="title" autocomplete="off" placeholder="请输入地区或部门"
                           class="layui-input" id="norm">
                </div>
            </div>
            <input type="button" class="layui-btn layui-btn-sm" lay-event="select" id="select" value="查询"></input>
        </form>
    </div>
    <table class="layui-hide" id="demo" lay-filter="test"></table>
</div>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <div class="layui-inline" lay-event="add"><i class="layui-icon layui-icon-add-1"></i></div>
        <div class="layui-inline" lay-event="delete"><i class="layui-icon layui-icon-delete"></i></div>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    var table;
    //使用什么就加什么,没用的可以删掉
    layui.use(['laydate', 'laypage', 'layer', 'jquery', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
        var layer = layui.layer //弹层
            , $ = layui.jquery//使用ajax
            , laydate = layui.laydate;
        table = layui.table;//表格




        //执行一个 table 实例
        table.render({
            elem: '#demo'
            , id: 'WageNorm'
            , height: 500
            , url: '/logisticsWageNorm/select'//数据接口
            , title: '用户表'
            , page: true //开启分页
            , toolbar: '#toolbarDemo' //开启工具栏，此处显示default默认图标，可以自定义模板，详见文档
            , totalRow: true //开启合计行
            , cols: [[ //表头,sort排序
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'moneyId', title: 'ID', width: 80, sort: true}
                , {field: 'mapName', title: '地区', width: 100}
                , {field: 'postName', title: '员工职位', width: 150}
                , {field: 'normBasepay', title: '基本工资', width: 110, sort: true}
                , {field: 'normPost', title: '岗位工资', width: 100}
                , {field: 'normSubsidy', title: ' 补贴', width: 100}
                , {fixed: 'right', width:120, align: 'center', toolbar: '#barDemo'}
            ]]
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 2,
                        area: ['700px', '600px'],
                        fixed: false, //不固定
                        maxmin: true,
                        content: '/log-wage/logWageNormForm.html'
                    });
                    break;
                case 'delete':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        let moneyId = "";
                        for (let i = 0; i < data.length; i++) {
                            moneyId += data[i].moneyId + ",";
                        }
                        moneyId= moneyId.substr(0, moneyId.length - 1);
                        let url = "/logisticsWageNorm/batch";
                        let data_ = {moneyId:moneyId};
                        console.info(data_)
                        $.post(url, data_, function (map) {
                            if (map.state == 1) {
                                table.reload('WageNorm')
                                layer.msg(map.msg);
                            } else {
                                layer.msg(map.msg)
                            }
                        }, "json")
                    }
            }
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    let url = "/logisticsWageNorm/delete";
                    let data_ = {moneyId: data.moneyId};
                    $.post(url, data_, function (map) {
                        if (map.state == 0) {
                            layer.close(map.message());
                        }
                    }, "json")
                    //向服务端发送删除指令
                });
            }else if (layEvent === 'edit') {//编辑操作
                layer.open({
                    type: 2
                    , area: ['800px', '600px']
                    , fixed: false //不固定位置
                    , maxmin: true
                    ,title:'个人工资信息'
                    , content: '/log-wage/logWageNormForm.html?moneyId='+data.moneyId
                    , success: function () {//第二种方法 打开成功后操作子页面
                    }
                });
            }
        });

    });


    $(function (){
        $("#select").on("click",function (){
            var data_={
                norm: $("#norm").val(),
            };
            console.info(data_);
            //执行重载
            table.reload('WageNorm', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where:data_
            });
        })
    })
</script>
</body>
</html>
